package com.fas.web.controller.system;

import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.entity.SysDept;
import com.fas.common.core.domain.entity.SysUser;
import com.fas.system.domain.FasBuilding;
import com.fas.system.domain.FasEquipment;
import com.fas.system.domain.FasFacilities;
import com.fas.system.domain.vo.StatisticalVo;
import com.fas.system.mapper.*;
import com.fas.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fas.common.config.RuoYiConfig;
import com.fas.common.utils.StringUtils;

import java.sql.SQLSyntaxErrorException;

/**
 * 首页
 *
 * @author ruoyi
 */
@RestController
public class SysIndexController
{
    /** 系统基础配置 */
    @Autowired
    private RuoYiConfig ruoyiConfig;

    private ISysUserService userService;

    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private FasBuildingMapper buildingMapper;
    @Autowired
    private FasEquipmentMapper equipmentMapper;

    @Autowired
    private FasFacilitiesMapper fasFacilitiesMapper;
    @Autowired
    private SysDeptMapper deptMapper;
    /**
     * 访问首页，提示语
     */
    @RequestMapping(value = "/",produces = "text/html;charset=utf-8")
    public String index()
    {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", ruoyiConfig.getName(), ruoyiConfig.getVersion());
    }

    /**
     * 首页统计
     * */
    @RequestMapping("/statistical")
    public AjaxResult statistical() {
        StatisticalVo vo = new StatisticalVo();
        //总员工
        Long countUsers = userMapper.countUsers(new SysUser());
        vo.setTotalWorkers(countUsers);
        //建筑
        Long countBuildings = buildingMapper.countBuildings(new FasBuilding());
        vo.setTotalBuildings(countBuildings);
        //设备总数
        Long totalEqu = equipmentMapper.countEquipment(new FasEquipment());
        vo.setTotalEquipment(totalEqu);
        FasEquipment query = new FasEquipment();
        query.setStatus(1);
        //异常设备数
        Long abnormalEquipment =  equipmentMapper.countEquipment(query);
        vo.setAbnormalEquipment(abnormalEquipment);
        Long totalFasFacilities = fasFacilitiesMapper.countFasFacilities(new FasFacilities());
        vo.setTotalFasFacilities(totalFasFacilities);
        SysDept params = new SysDept();
        params.setDeptType("2");
        Long totalMaintain = deptMapper.countDeptNumber(params);
        vo.setTotalMaintain(totalMaintain);
        return AjaxResult.success(vo);
    }
}
